from api.base import BaseSellerApi
from common.encry_decry import md5
from common.file_load import read_yml


class SellerLoginAPI(BaseSellerApi):
    """卖家登录接口"""
    def __init__(self,username,password):
        super().__init__()
        self.url = f"{self.host}/seller/login"
        self.method = "get"
        self.params = {
            "username": username,
            "password": md5(password),
            "captcha": read_yml("/config/common.yml")["captcha"],
            "uuid": "jdajhjakd"
        }

class SellerGoodsAPI(BaseSellerApi):
    """卖家添加商品"""
    def __init__(self):
        super().__init__()
        self.url = f"{self.host}/seller/goods"
        self.method = "post"
        self.json = {
            "brand_id": "",
            "category_id": 83,
            "category_name": "",
            "goods_name": "不锈钢锅",
            "sn": "83721",
            "price": "200",
            "mktprice": "100",
            "cost": "10",
            "weight": "1",
            "goods_gallery_list": [{
                "img_id": -1,
                "original": "http://59.36.173.55:7000/statics/attachment/goods/2024/4/25/11/07091778.jpeg",
                "sort": 0
            }],
            "quantity": 9999999,
            "goods_transfee_charge": 1,
            "has_changed": 0,
            "market_enable": 1,
            "template_id": 0,
            "exchange": {
                "category_id": "",
                "enable_exchange": 0,
                "exchange_money": 0,
                "exchange_point": 0
            },
            "shop_cat_id": 118,
            "meta_description": "",
            "meta_keywords": "",
            "page_title": "",
            "goods_params_list": [],
            "sku_list": [],
            "intro": "<p>这是我的商品信息</p>"
        }

class SellerPutGoods(BaseSellerApi):
    """卖家修改商品"""
    def __init__(self,goods_id):
        super().__init__()
        self.url = f"{self.host}/seller/goods/{goods_id}"
        self.method = "put"
        self.json = {
            "brand_id": "",
            "category_id": 83,
            "category_name": "",
            "goods_name": "不锈钢锅",
            "sn": "83721",
            "price": "200",
            "mktprice": "100",
            "cost": "10",
            "weight": "1",
            "goods_gallery_list": [{
                "img_id": -1,
                "original": "http://59.36.173.55:7000/statics/attachment/goods/2024/4/25/11/07091778.jpeg",
                "sort": 0
            }],
            "quantity": 9999999,
            "goods_transfee_charge": 1,
            "has_changed": 0,
            "market_enable": 1,
            "template_id": 0,
            "exchange": {
                "category_id": "",
                "enable_exchange": 0,
                "exchange_money": 0,
                "exchange_point": 0
            },
            "shop_cat_id": 118,
            "meta_description": "",
            "meta_keywords": "",
            "page_title": "",
            "goods_params_list": [],
            "sku_list": [],
            "intro": "<p>这是我的商品信息</p>"
        }

class SellerGoodsUnder(BaseSellerApi):
    """卖家下架商品"""
    def __init__(self,goods_ids:list):
        super().__init__()
        goods_ids = [str(x) for x in goods_ids]
        # 将遍历得到得列表数据提取出来
        goods_ids = ",".join(goods_ids)
        self.url = f"{self.host}/seller/goods/{goods_ids}/under"
        self.method = "put"

class SellerGoodsRecycle(BaseSellerApi):
    """商家将商品放入回收站"""
    def __init__(self,goods_ids:list):
        super().__init__()
        goods_ids = [str(x) for x in goods_ids]
        # 将遍历得到得列表数据提取出来
        goods_ids = ",".join(goods_ids)
        self.url = f"{self.host}/seller/goods/{goods_ids}/recycle"
        self.method = "put"

class SellerGoodsGoods(BaseSellerApi):
    """商家彻底删除商品"""
    def __init__(self,goods_ids:list):
        super().__init__()
        goods_ids = [str(x) for x in goods_ids]
        # 将遍历得到得列表数据提取出来
        goods_ids = ",".join(goods_ids)
        self.url = f"{self.host}/seller/goods/{goods_ids}"
        self.method = "delete"

class SellerDelivery(BaseSellerApi):
    """订单发货"""
    def __init__(self,order_sn):
        super().__init__()
        self.url = f"{self.host}/seller/trade/orders/{order_sn}/delivery"
        self.method = "post"
        self.data = {
            "ship_no":"aaaaaaaa",
            "logi_id":"12",
            "logi_name":"中通"
        }

class SellerPay(BaseSellerApi):
    """确认收款"""
    def __init__(self,order_sn,pay_price):
        super().__init__()
        self.url = f"{self.host}/seller/trade/orders/{order_sn}/pay"
        self.method = "post"
        self.data = {
            "pay_price":pay_price
        }

class ManagerSkus(BaseSellerApi):
    """商品sku相关API"""
    def __init__(self,goods_id):
        super().__init__()
        self.url = f"{self.host}/seller/goods/{goods_id}/skus"
        self.method = "get"

if __name__ == '__main__':
    pass
    # goods_ids = [1,2,3]
    # goods_ids = [str(x) for x in goods_ids]
    # print(goods_ids)
    # goods_ids = ",".join(goods_ids)
    # print(goods_ids)
    # resp = SellerLoginAPI(username="shamoseller", password="fafd8b5f5d11048e8078b66ab075acb3").request()
    # print(resp.text())